define(function(require){
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var websocket = null;	
	//加入页面
	var WindowContainer = require("$UI/system/components/justep/windowContainer/windowContainer");
	//加入页面code
<<<<<<< HEAD
    var yuyan =999; 
=======
    var yuyan =666; 
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
    var datatui="";
    var datajie="";
    var row="";
    var wind="";
    var websocket="";
    var dengzi="";
    var dddd="";
    var windowContainer="";
    var windowContainer2="";
    var windowContainer3="";
    var windowContainer4="";
    var windowContainer5="";
    localStorage.dengdais = "";
    window.tonghuazhuantai=1;
    //引入极光推送
<<<<<<< HEAD
  //  var jpushInstance = require("./jpush");
	require("$UI/system/lib/cordova/cordova");
	require("cordova!jpush-phonegap-plugin");
	require("cordova!cordova-plugin-media");
	require("cordova!cordova-plugin-camera");
	require("cordova!com.justep.cordova.plugin.voiceManager");
=======
    var jpushInstance = require("./jpush");
	require("$UI/system/lib/cordova/cordova");
	require("cordova!cn.jpush.phonegap.JPushPlugin");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
    var quxiao=function(){
            $('#wxloading').css("display","none");
         }
	var Model = function(){
	  
		this.callParent();
	};
	
   //默认加载蒙语页面
   Model.prototype.modelModelConstruct = function(event){	   
<<<<<<< HEAD
              
=======
            
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
	            //获取windowContainer1组件
	             windowContainer = this.comp("windowContainer1");
	             windowContainer2 = this.comp("windowContainer2");
	             windowContainer3 = this.comp("windowContainer3");
	             windowContainer4 = this.comp("windowContainer4");
	             windowContainer5 = this.comp("windowContainer5");
            
            //汉语蒙语切换以后加载页面
            if(yuyan==666){   
	            var src = require.toUrl("$UI/longrange/h/hanyu.w");
	            var src2 = require.toUrl("$UI/longrange/h/hanyu2.w");
	            var src3 = require.toUrl("$UI/longrange/h/hanyu3.w");
	            var src4 = require.toUrl("$UI/longrange/h/hanyu4.w");
	            var src5 = require.toUrl("$UI/longrange/g/posinal.w");
            window.menghan=2;
            }else{
	             var src = require.toUrl("$UI/longrange/m/mongol.w");
	             var src2 = require.toUrl("$UI/longrange/m/mongol2.w");
	             var src3 = require.toUrl("$UI/longrange/m/mongol3.w");
	             var src4 = require.toUrl("$UI/longrange/m/mongol4.w");
	             var src5 = require.toUrl("$UI/longrange/g/posinal.w");
            window.menghan=1;
            }
            
         
	};
	
	//接受状态码，切换语言页面
    Model.prototype.modelParamsReceive = function(event){
       
                 yucode = event.params.yucode;
       
		      if(yucode==1){ 
		                yuyan=999;
		         }else if(yucode==2){    
		                yuyan=666;
		         } 
		              
	             windowContainer = this.comp("windowContainer1");
	             windowContainer2 = this.comp("windowContainer2");
	             windowContainer3 = this.comp("windowContainer3");
	             windowContainer4 = this.comp("windowContainer4");
	             windowContainer5 = this.comp("windowContainer5");          
            if(yuyan==666){             
	            var src = require.toUrl("$UI/longrange/h/hanyu.w");
	            var src2 = require.toUrl("$UI/longrange/h/hanyu2.w");
	            var src3 = require.toUrl("$UI/longrange/h/hanyu3.w");
	            var src4 = require.toUrl("$UI/longrange/h/hanyu4.w");
	            var src5 = require.toUrl("$UI/longrange/g/posinal.w");
                window.menghan=2;
            }else{
	             var src = require.toUrl("$UI/longrange/m/mongol.w");
	             var src2 = require.toUrl("$UI/longrange/m/mongol2.w");
	             var src3 = require.toUrl("$UI/longrange/m/mongol3.w");
	             var src4 = require.toUrl("$UI/longrange/m/mongol4.w");
	             var src5 = require.toUrl("$UI/longrange/g/posinal.w");
                 window.menghan=1;
            }
		          windowContainer.setSrc(src);
          windowContainer.load();
          windowContainer2.setSrc(src2);
          windowContainer2.load();
          windowContainer3.setSrc(src3);
          windowContainer3.load();
          windowContainer4.setSrc(src4);
          windowContainer4.load();
          windowContainer5.setSrc(src5);
          windowContainer5.load();
          this.modelLoad(event);
		           
	};
   //动态加载底部按钮图片
	Model.prototype.contents1ActiveChanged = function(event){
        var str = location.href;
		var num = str.indexOf("!");
		str = str.substr(num + 1);
		var home = this.comp("homeBtn");
		var yao = this.comp("yaoBtn");
		var zhuan = this.comp("zhuanBtn");
		var xuexi = this.comp("xuexiBtn");
		var geren= this.comp("gerenBtn");
		
		if (str === "main//(#!content2)") {
			home.set({
				"icon" : "img:$UI/longrange/img/h.png|"
			});
			
			yao.set({
				"icon" : "img:$UI/longrange/img/ys.png|"

			});	
				
			zhuan.set({
				"icon" : "img:$UI/longrange/img/zs.png|"

			});		
			
			xuexi.set({
				"icon" : "img:$UI/longrange/img/xs.png|"

			});	
				
			geren.set({
				"icon" : "img:$UI/longrange/img/gs.png|"

			});	
		}
		if (str === "main//(#!content3)") {
			home.set({
				"icon" : "img:$UI/longrange/img/hs.png|"
			});
			yao.set({
				"icon" : "img:$UI/longrange/img/y.png|"

			});		
			zhuan.set({
				"icon" : "img:$UI/longrange/img/zs.png|"

			});		
			xuexi.set({
				"icon" : "img:$UI/longrange/img/xs.png|"

			});		
			geren.set({
				"icon" : "img:$UI/longrange/img/gs.png|"

			});
		
		}
		if (str === "main//(#!content4)") {
			home.set({
				"icon" : "img:$UI/longrange/img/hs.png|"
			});
			yao.set({
				"icon" : "img:$UI/longrange/img/ys.png|"

			});		
			zhuan.set({
				"icon" : "img:$UI/longrange/img/z.png|"

			});		
			xuexi.set({
				"icon" : "img:$UI/longrange/img/xs.png|"

			});		
			geren.set({
				"icon" : "img:$UI/longrange/img/gs.png|"

			});
			
		}
		if (str === "main//(#!content5)") {
			home.set({
				"icon" : "img:$UI/longrange/img/hs.png|"
			});
			yao.set({
				"icon" : "img:$UI/longrange/img/ys.png|"

			});		
			zhuan.set({
				"icon" : "img:$UI/longrange/img/zs.png|"

			});		
			xuexi.set({
				"icon" : "img:$UI/longrange/img/x.png|"

			});		
			geren.set({
				"icon" : "img:$UI/longrange/img/gs.png|"

			});
			
		}
		if (str === "main//(#!content6)") {
			home.set({
				"icon" : "img:$UI/longrange/img/hs.png|"
			});
			yao.set({
				"icon" : "img:$UI/longrange/img/ys.png|"

			});		
			zhuan.set({
				"icon" : "img:$UI/longrange/img/zs.png|"

			});	
				
			xuexi.set({
				"icon" : "img:$UI/longrange/img/xs.png|"

			});	
				
			geren.set({
				"icon" : "img:$UI/longrange/img/g.png|"

			});
			
		}
		
	};
    //关联websocket，并接受推送过来的消息
	Model.prototype.modelLoad = function(event){	
	     
		if(window.token != null){ 
	       
		    wind=this.comp("windowDialog1");
	        datatui=this.comp("tuisong");
<<<<<<< HEAD
	        dddd=this;    
=======
	       dddd=this;
	    
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
	     //  var  ddd=dddd.comp("jindengtai");
	        datatui.clear();
	        //判断当前浏览器是否支持WebSocket
		    if ('WebSocket' in window) {
<<<<<<< HEAD
			   websocket = new WebSocket("ws://"+window.webyuming+"/ws/users/login?login-token="+window.token+"");
		     } else {
		    	websocket = new SockJS(window.yuming + "/sockjs/ws/users/login?login-token="+window.token+"");
=======
			   websocket = new WebSocket("wss://"+window.webyuming+"/ws/users/login?login-token="+window.token+"");
		     } else {
			websocket = new SockJS(window.yuming + "/sockjs/ws/users/login?login-token="+window.token+"");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
		     }
		     //接受推送过来的消息
		     websocket.onmessage = function(event) {
                      var d = event.data;
                          //console.log(event.data)
                          datajie = JSON.parse(d);
                         
		              var type = datajie.type;
		                  //登陆成功以后
	                      if(type  == "LOGIN_USER") {

	                       }
	                       //接受新消息
                          if(type  == "NEW_NOTICE"){

	                       }
	                        //接受视频通话接受 
	                       if(type == "NEW_VIDEO"){
	                                //专家存储房间路径，id,牧民id 
	                                window.roomurl=datajie.videoconnect.url+datajie.videoconnect.roomid;
	                            //    window.location=datajie.videoconnect.url+datajie.videoconnect.roomid;
	                              //  console.log(window.roomurl)
                                    window.roomid=datajie.videoconnect.hid;
                                    window.hid=datajie.videoconnect.hid;
                                    //生成json数据
		                        var zuotis = { defaultValues : [{
                                               "id" :datajie.videoconnect.id,
                                               "createTime" :datajie.videoconnect.createTime,
                                               "updateTime" :datajie.videoconnect.updateTime,
						                       "eid" :datajie.videoconnect.eid,
						                       "hid" :datajie.videoconnect.hid,
						                       "roomid":datajie.videoconnect.roomid,
						                       "url":datajie.videoconnect.url,
						                       "time" :datajie.videoconnect.time,
						                       "type" :datajie.videoconnect.type,
						                       "headurl" :"ddd",
						                       "username" :"fff"
                                               }]}
                                     //把数据存储在      tuisong组件里    
                                    datatui.newData(zuotis);
                                    //获取最新一调数据
                                    row=datatui.getLastRow().toJson();
                                    //打开通知页面
                                   //  location.href=datajie.videoconnect.url+datajie.videoconnect.roomid;
						           wind.open({
						               params:{
						                   rowdata:row,
						                     }
						                 });
	                       		}
	                       //接受專家通知以后推过来的状态		
	                       if(type== "VIDEO_RETURN"){
	           
						            if(datajie.returnVc.ifOrNot == 1){
						              //  localStorage.dengdai.close();
						                //justep.Shell.showPage("main"); 
						              //   var yanpind=dddd.getInnerModel();
						             // alert(dddd.getInnerModel())
						               ddd=dddd.comp("windowContainer3");
						                var jinshi=ddd.getInnerModel();
						                jinshi.comp('jindengtai').close();
						              //   var tongcc=yanpind.comp('windowDialog3').getInnerModel();
						             // yanpind.com;
						            //    dddd.windowEnsure();
						                justep.Shell.showPage("shiroom");
						                
						            } else{
						                
						               $('.wx_loading_inner').html("专家拒接接受！");
							           $('#wxloading').css("display","block"); 
							           setTimeout(quxiao,2000);
						            }  
	                       }
	                         //牧民点击挂断以后的状态
					          if(type == "VIDEO_STOP_H"){
					            /*   $('.wx_loading_inner').html("本次视频通话结束！");
						           $('#wxloading').css("display","block"); 
						           setTimeout(quxiao,2000);*/
<<<<<<< HEAD
						          // window.tonghuazhuantai=2;	 
						           justep.Shell.closeAllOpendedPages();     
						           justep.Shell.showPage("main");
						           
=======
						          // window.tonghuazhuantai=2;	      
						           justep.Shell.showPage("main");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
					          }
					          //专家点击挂断以后的状态
					          if(type == "VIDEO_STOP_E"){
					              // console.log("22222")
					              /* $('.wx_loading_inner').html("本次视频通话结束！");
						           $('#wxloading').css("display","block"); 
						           setTimeout(quxiao,2000);*/
<<<<<<< HEAD
						           justep.Shell.closeAllOpendedPages();
						           justep.Shell.showPage("main");
						           
						           
=======
						           justep.Shell.showPage("main");
>>>>>>> db50113a5feef0605bbbc3a649d7e9809a12c455
					          }
					        }
						 } 

       // jpushInstance.onDeviceReady();
      //  jpushInstance.onOpenNotification();
        // 加载完成
   /*     function onDeviceReady() {
            window.plugins.jPushPlugin.init();

            window.plugins.jPushPlugin.openNotificationInAndroidCallback = function(data) {//点击消息窗口
                alert(555)
                var json=eval("("+data+")");//转为json对象
                var content=json.extras["cn.jpush.android.ALERT"];//消息内容
                var url=json.extras["cn.jpush.android.EXTRA"].sss;
                alert(content);
                alert(url);
                // console.log(json);
                //  console.log(content);
               // location.href=url;
            }
         }*/
		};
	
  
	       return Model;
       });